package godis

import (
	"fmt"
	"time"
)

const (
	AttrExpire = "expr"
	AttrNX    = "nx"
	AttrXX     = "xx"
)

type OperationAttr struct {
	Name  string
	Value interface{}
}

type OperationAttrs []*OperationAttr

func (self OperationAttrs) Find(name string) *InterfaceResult {

	for _, attr := range self {
		if attr.Name == name {
			return NewInterfaceResult(attr.Value, nil)
		}
	}

	return NewInterfaceResult(nil, fmt.Errorf("expire attl found error %s", name))
}

func WithExpire(t time.Duration) *OperationAttr {
	return &OperationAttr{
		Name:  AttrExpire,
		Value: t,
	}
}

func WithNX() *OperationAttr {

	return &OperationAttr{
		Name: AttrNX,
		Value: struct {}{},
	}

}

func WithXX() *OperationAttr {

	return &OperationAttr{
		Name: AttrXX,
		Value: struct {}{},
	}

}
